import axios from "axios";

const port="http://localhost:3000"

//渲染数据库列表数据
export const getAll = async (keyword) => {
    // console.log(keyword);
    let res;
    if (keyword) {
        res = await axios.get(`${port}/books?keyword=${keyword}`)
    } else {
        res = await axios.get(`${port}/books`)
    }
    return res.data;
}
//删除功能

export const delBook= async (id)=>{
    let res=await axios.delete(`${port}/books/${id}`)
    return res.data 
}

//新增功能

export const addBook=async(obj)=>{
    let res=await axios.post(`${port}/books`,obj)
    return res.data
}

//修改功能

export const editBook = async (id, obj) => {
    let res = await axios.put(`${port}/books/${id}`, obj)
    return res.data;
}

//通过id获取指定内容用于渲染修改列表内容
export const getById = async (id) => {
    let res = await axios.get(`${port}/books/${id}`)
    // console.log(res);
    return res.data;
}